package com.kyrie.lib_sys.rocketMQ.rocketmqController;

import com.kyrie.lib_sys.common.entity.Result;
import com.kyrie.lib_sys.common.pojo.dto.AuthorDTO;
import com.kyrie.lib_sys.rocketMQ.Producer.MessageProducerService;
import com.kyrie.lib_sys.rocketMQ.pojo.UserPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * mq测试controller
 *
 * @author heefM
 * @date 2025-
 */
@RequestMapping("/rocketmq")
@RestController
public class TestController {

    @Autowired
    private MessageProducerService messageProducerService;

    /**
     * 发送同步消息
     *
     * @param msg
     * @return
     */
    @GetMapping("/send")
    public String sendMessage(@RequestParam String msg) {
        messageProducerService.sendSyncMessage("TestTopic", msg);
        return "消息已发送: " + msg;
    }

    /**
     * 发送带Tag的消息，格式为 Topic:Tag
     *
     * @param msg
     * @return
     */
    @GetMapping("/send/tag")
    public String sendMessageWithTag(@RequestParam String msg) {
        messageProducerService.sendMessageWithTag("TestTopic", "TagA", msg);
        return "带Tag的消息已发送: " + msg;
    }

    /**
     * 发送延迟消息
     *
     * @param msg
     * @param delayLevel
     * @return
     */
    @GetMapping("/send/delay")
    public String sendDelayMessage(@RequestParam String msg, @RequestParam int delayLevel) {
        messageProducerService.sendDelayMessage("TestTopic", msg, delayLevel);
        return "延迟消息已发送: " + msg + ", 延迟级别: " + delayLevel;
    }

    /**
     * 发送对象消息
     * @param userPojo
     * @return
     */
    @PostMapping("/send/pojo")
    public Result sendPojoMessage(@RequestBody UserPojo userPojo) {
        messageProducerService.sendSyncMessage("PojoTopic", userPojo);
        return Result.success("发送pojo对象消息成功: " + userPojo);
    }
}